<title>Admin | Manage Users</title>
<script>
    $("ul li").each(function() {
        if ($(this).attr("key") == "adminusers") {
            $(this).addClass("active");
        }
    });
</script>
<div id="view-content">    
    <div class="row-fluid">
        <h2>List of Members</h2>
        <div class="well">
            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Contact No.</th>
                        <th>Info</th>
                        <th>Operations</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $i = 1;
                    foreach ($this->allUsers as $value) :
                        ?>
                        <tr>
                            <td><?= $i++; ?></td>
                            <td><?= $value->name; ?></td>
                            <td><?= $value->email; ?></td>
                            <td>
                                <?php
                                if ($value->contact_number != null) {
                                    $djson = json_decode($value->contact_number);
                                    echo '<ul><li>' . $djson->contact->primary_contact . ' (Primary)</li><li>' . $djson->contact->secondary_contact . '</li></ul>';
                                }
                                ?>
                            </td>
                            <td>                                      
                                <?php
                                if ($value->confirm) {
                                    echo '<button class="btn btn-mini btn-success" title="Verified"><i class="icon-white icon-ok-sign"></i></button> &nbsp;';
                                } else {
                                    echo '<button class="btn btn-mini btn-info">Waiting for Verification</button> &nbsp;';
                                }
                                if ($value->blocked) {
                                    echo '<button class="btn btn-mini btn-danger" title="Blocked"><i class="icon-white icon-ban-circle"></i></button>';
                                }
                                ?>                                
                            </td>
                            <td>
                                <?php if ($value->blocked) { ?>
                                    <a class="btn btn-mini btn-success" href="<?= $this->url(array('id' => $value->id), "adminusersunblock"); ?>" title="Un-Block this user"><i class="icon-ok-circle icon-white"></i> Un-Block</a>
                                <?php } else { ?>
                                    <a class="btn btn-mini btn-danger" href="<?= $this->url(array('id' => $value->id), "adminusersblock"); ?>" title="Block this user"><i class="icon-ban-circle"></i> Block</a>
                                    <?php
                                }
                                #check for 2 days and option for delete
                                $reg_date = new DateTime($value->reg_date);
                                $curr_date = new DateTime(date('Y-m-d', date('U')));
                                $days = $curr_date->diff($reg_date)->format('%a');
                                if (!$value->confirm && $days >= 2) {
                                    ?>
                                    <a class="btn btn-mini btn-danger" href="<?= $this->url(array('id' => $value->id), "delete-user"); ?>" title="Delete this user"><i class="icon-trash icon-white"></i> Delete User</a>
                                <?php } ?>
                                <a href="<?= $this->url(array('id' => $value->id), 'delete-user'); ?>" class="btn btn-danger btn-mini"><i class="icon-white icon-trash"></i></a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>

            </table>

        </div>        
    </div>


</div>